package com.allst.dubbo;

import com.allst.dubbo.service.HelloService;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.util.concurrent.Future;

/**
 * @author June
 * @since 2021年03月
 */
public class XmlConsumerMain {

    public static void main(String[] args) throws IOException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consumer.xml");
        HelloService service = (HelloService) context.getBean("helloService");
        while (true) {
            int read = System.in.read();
            if (read > 0) {
                try {
                    String hello = service.sayHiOfTime("Hi", 1000);
                    // 利用Future模式来获取
                    Future<Object> future = RpcContext.getContext().getFuture();
                    System.out.println("result : " + hello);
                    System.out.println("future result : " + future.get());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                break;
            }
        }
    }
}
